package me.obstsalat.guildera;

import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;

public class g_block_res {
	private static guildera plugin;
	private static int blockPermissionTable[] = new int[125];
	
	g_block_res(guildera pl) { 
		plugin = pl;
		blockPermissionTable[0] = 0;
		blockPermissionTable[1] = 20;
		blockPermissionTable[2] = 0;
		blockPermissionTable[3] = 0;
		blockPermissionTable[4] = 20;
		blockPermissionTable[5] = 10;
		blockPermissionTable[6] = 0;
		blockPermissionTable[7] = 0;
		blockPermissionTable[8] = 0;
		blockPermissionTable[9] = 0;
		blockPermissionTable[10] = 0;
		blockPermissionTable[11] = 0;
		blockPermissionTable[12] = 0;
		blockPermissionTable[13] = 0;
		blockPermissionTable[14] = 0;
		blockPermissionTable[15] = 0;
		blockPermissionTable[16] = 0;
		blockPermissionTable[17] = 10;
		blockPermissionTable[18] = 0;
		blockPermissionTable[19] = 0;
		blockPermissionTable[20] = 25;
		blockPermissionTable[21] = 0;
		blockPermissionTable[22] = 20;
		blockPermissionTable[23] = 22;
		blockPermissionTable[24] = 20;
		blockPermissionTable[25] = 0;
		blockPermissionTable[26] = 10;
		blockPermissionTable[27] = 35;
		blockPermissionTable[28] = 35;
		blockPermissionTable[29] = 35;
		blockPermissionTable[30] = 0;
		blockPermissionTable[31] = 0;
		blockPermissionTable[32] = 0;
		blockPermissionTable[33] = 35;
		blockPermissionTable[34] = 0;
		blockPermissionTable[35] = 2;
		blockPermissionTable[36] = 0;
		blockPermissionTable[37] = 0;
		blockPermissionTable[38] = 0;
		blockPermissionTable[39] = 0;
		blockPermissionTable[40] = 0;
		blockPermissionTable[41] = 35;
		blockPermissionTable[42] = 35;
		blockPermissionTable[43] = 0;
		blockPermissionTable[44] = 20;
		blockPermissionTable[45] = 20;
		blockPermissionTable[46] = 20;
		blockPermissionTable[47] = 32;
		blockPermissionTable[48] = 20;
		blockPermissionTable[49] = 45;
		blockPermissionTable[50] = 0;
		blockPermissionTable[51] = 0;
		blockPermissionTable[52] = 0;
		blockPermissionTable[53] = 10;
		blockPermissionTable[54] = 0;
		blockPermissionTable[55] = 35;
		blockPermissionTable[56] = 0;
		blockPermissionTable[57] = 35;
		blockPermissionTable[58] = 0;
		blockPermissionTable[59] = 0;
		blockPermissionTable[60] = 0;
		blockPermissionTable[61] = 0;
		blockPermissionTable[62] = 0;
		blockPermissionTable[63] = 10;
		blockPermissionTable[64] = 10;
		blockPermissionTable[65] = 10;
		blockPermissionTable[66] = 35;
		blockPermissionTable[67] = 20;
		blockPermissionTable[68] = 10;
		blockPermissionTable[69] = 20;
		blockPermissionTable[70] = 20;
		blockPermissionTable[71] = 35;
		blockPermissionTable[72] = 10;
		blockPermissionTable[73] = 0;
		blockPermissionTable[74] = 0;
		blockPermissionTable[75] = 35;
		blockPermissionTable[76] = 35;
		blockPermissionTable[77] = 20;
		blockPermissionTable[78] = 0;
		blockPermissionTable[79] = 0;
		blockPermissionTable[80] = 0;
		blockPermissionTable[81] = 0;
		blockPermissionTable[82] = 0;
		blockPermissionTable[83] = 0;
		blockPermissionTable[84] = 0;
		blockPermissionTable[85] = 10;
		blockPermissionTable[86] = 0;
		blockPermissionTable[87] = 25;
		blockPermissionTable[88] = 50;
		blockPermissionTable[89] = 35;
		blockPermissionTable[90] = 0;
		blockPermissionTable[91] = 0;
		blockPermissionTable[92] = 0;
		blockPermissionTable[93] = 20;
		blockPermissionTable[94] = 20;
		blockPermissionTable[95] = 0;
		blockPermissionTable[96] = 10;
		blockPermissionTable[97] = 20;
		blockPermissionTable[98] = 20;
		blockPermissionTable[99] = 20;
		blockPermissionTable[100] = 20;
		blockPermissionTable[101] = 35;
		blockPermissionTable[102] = 25;
		blockPermissionTable[103] = 0;
		blockPermissionTable[104] = 0;
		blockPermissionTable[105] = 0;
		blockPermissionTable[106] = 0;
		blockPermissionTable[107] = 10;
		blockPermissionTable[108] = 20;
		blockPermissionTable[109] = 20;
		blockPermissionTable[110] = 0;
		blockPermissionTable[111] = 0;
		blockPermissionTable[112] = 25;
		blockPermissionTable[113] = 25;
		blockPermissionTable[114] = 25;
		blockPermissionTable[115] = 0;
		blockPermissionTable[116] = 52;
		blockPermissionTable[117] = 42;
		blockPermissionTable[118] = 42;
		blockPermissionTable[119] = 20;
		blockPermissionTable[120] = 0;
		blockPermissionTable[121] = 20;
		blockPermissionTable[122] = 0;
		blockPermissionTable[123] = 35;
		blockPermissionTable[124] = 35;
	}

	public void overrideTable() {
		blockPermissionTable[23] = plugin.config.getInt("req_dispenser");
		blockPermissionTable[117] = plugin.config.getInt("req_brewing");
		blockPermissionTable[118] = plugin.config.getInt("req_brewing");
		blockPermissionTable[116] = plugin.config.getInt("req_enchantment");
		
	}
	
	public boolean onBlockPlace(BlockPlaceEvent event) {
		Player ply = event.getPlayer();
		Block bl = event.getBlockPlaced();
		if(!plugin.checkViableWorld(ply.getWorld())) {
			return false;
		}
		if(!ply.isOp())  {
			boolean b1 = true;
			for(guild g : plugin.guilds) {
				if(g.hasMember(ply.getName())) {
					b1 = false;
					if(blockPermissionTable[bl.getTypeId()] > g.getLevel()) {
						event.setBuild(false);
						ply.sendMessage("Your guild needs to be level " + blockPermissionTable[bl.getTypeId()] + " to use this material. Your current guild level is " + g.getLevel() + ".");
					}
				}
			}
			if(b1 && blockPermissionTable[bl.getTypeId()] > plugin.config.getInt("startlevel")) {
				event.setBuild(false);
				ply.sendMessage("You need to be in a guild to use this material.");
			}
			
		}
		return !event.canBuild();
	}
}
